function Html_Page(gui, user, date, options, message) {
  this._gui = gui;
  this._user = user;
  this._date = date;
  this._options = options;
  this._message = message;

  this._createElements();
};

Html_Page.prototype._createElements = function() {
  var _self = this;

  // Data
  var plugins = (this._message['plugins'] && this._message['plugins'].d) ? this._message['plugins'].d : [];
  var menu_id = (this._message['i']) ? this._message['i'] : null;
  var page = (this._message[0] && this._message[0].d[0]) ? this._message[0].d[0] : pz_page.instance();
  page.menu_id = menu_id;
  var plugin_instance = pz_plugin_instance.instance();
  plugin_instance.menu_id = menu_id;
  var instances = (this._message['instances'] && this._message['instances'].d) ? this._message['instances'].d : [];
  // Display
  tinyMCE.init( {
    // General options
    mode : "exact",
    elements : "page_content",
    theme : "advanced",

    plugins : "pdw,filebrowser,autolink,lists,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,wordcount,advlist",
    // Theme options
    theme_advanced_buttons1 : "pdw_toggle,save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontselect,fontsizeselect",
    theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
    theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
    theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak",
    theme_advanced_toolbar_location : "top",
    theme_advanced_toolbar_align : "left",
    theme_advanced_statusbar_location : "bottom",
    theme_advanced_resizing : true,

    file_browser_callback : 'filebrowser',
    pdw_toggle_on : "1",
    pdw_toggle_toolbars : "2,3,4",

    // Example content CSS (should be your site CSS)
    content_css : "css/content.css",
    theme_advanced_font_sizes : "10px,12px,13px,14px,16px,18px,20px,22px,24px,26px,28px,30px",
    font_size_style_values : "10px,12px,13px,14px,16px,18px,20px,22px,24px,26px,28px,30px",
    width : '1024px',
    height : '700px',

    // Drop lists for link/image/media/template dialogs
    template_external_list_url : "js/lists/template_list.js",
    external_link_list_url : "js/lists/link_list.js",
    external_image_list_url : "js/lists/image_list.js",
    media_external_list_url : "js/lists/media_list.js",
    // Style formats
    style_formats : [ {
      title : 'Bold text',
      inline : 'b'
    }, {
      title : 'Red text',
      inline : 'span',
      styles : {
        color : '#ff0000'
      }
    }, {
      title : 'Red header',
      block : 'h1',
      styles : {
        color : '#ff0000'
      }
    }, {
      title : 'Example 1',
      inline : 'span',
      classes : 'example1'
    }, {
      title : 'Example 2',
      inline : 'span',
      classes : 'example2'
    }, {
      title : 'Table styles'
    }, {
      title : 'Table row 1',
      selector : 'tr',
      classes : 'tablerow1'
    } ],

    // Replace values for the template plugin
    template_replace_values : {
      username : "Some User",
      staffid : "991234"
    }
  });

  this._gui.content.appendChild(document.createTextNode(page.content));

  for ( var i = 0, il = plugins.length; i < il; i++) {
    var tmp = plugins[i];
    var op = new Option(tmp.name);
    op._id = tmp.id;
    this._gui.plugins.options[this._gui.plugins.options.length] = op;
  }
  if (plugins.length > 0) {
    plugin_instance.plugin_id = plugins[0].id;
  }

//  var tr, td, elm;
//  for ( var i = 0, il = instances.length; i < il; i++) {
//    var tmp = instances[i];
//    tr = this._gui.instances.insertRow(-1);
//    tr.style.backgroundColor = (i % 2 == 1) ? '#ffffff' : '#cccccc';
//    tr.style.height = '30px';
//    td = tr.insertCell(-1);
//    elm = document.createElement('input');
//    elm.type = 'checkbox';
//    td.appendChild(elm);
//    td = tr.insertCell(-1);
//    td.style.paddingLeft = '10px';
//    td.appendChild(document.createTextNode(i + 1));
//    td = tr.insertCell(-1);
//    td.style.paddingLeft = '10px';
//    td.appendChild(document.createTextNode(tmp.name));
//    td = tr.insertCell(-1);
//    td.style.paddingLeft = '10px';
//    td.appendChild(document.createTextNode('{' + tmp.folder + ': ' + tmp.id + '}'));
//    td = tr.insertCell(-1);
//    elm = document.createElement('img');
//    td.appendChild(elm);
//    elm.src = 'image/edit.png';
//    elm.style.marginLeft = '10px';
//    elm.style.cursor = 'pointer';
//    var pos = DOMUtils.findPos(elm);
//    elm._tmp = tmp;
//    elm.onclick = function() {
//      var iframe = document.createElement('iframe');
//      iframe.width = '100%';
//      iframe.onload = function() {
//        _self._adjust.call(_self, iframe);
//      };
//      iframe.height = '1';
//      iframe.frameBorder = 0;
//      iframe.marginWidth = 0;
//      iframe.marginHeight = 0;
//      iframe.src = 'pluginback.php?i=' + this._tmp.id + '&p=' + this._tmp.folder;
//      var p = new ModulePopupBox();
//      p._open(iframe, {
//        pos : [ 50, pos[1] - 260 ],
//        width : 800,
//        height : 1,
//        t : '',
//        doc : document
//      });
//    };
//  }

  // Event
  this._gui.plugins.onchange = function() {
    plugin_instance.plugin_id = this.options[this.selectedIndex]._id;
  };
  this._gui.plugin_browse.onclick = function() {
    var p = new ModulePopupBox();

    var div = document.createElement('div');
    var iframe = document.createElement('iframe');
    iframe.src = 'adminplugin.php?m=' + menu_id;
    iframe.width = '100%';
    iframe.height = '400';
    iframe.frameBorder = 0;
    iframe.marginWidth = 0;
    iframe.marginHeight = 0;
    var table = document.createElement('table');
    table.cellPadding = 0;
    table.cellSpacing = 0;
    table.style.height = '50px';
    table.style.cursor = 'pointer';
    table.style.border = 'thick solid #cccccc';
    table.style.textAlign = 'center';
    table.style.fontWeight = 'bold';
    table.style.fontSize = '16px';
    table.style.letterSpacing = '1px';
    tr = table.insertRow(-1);
    td = tr.insertCell(-1);
    td.style.width = '150px';
    td.style.backgroundColor = '#dddddd';
    td.onmouseover = function() {
      this.style.backgroundColor = '#ffffff';
    };
    td.onmouseout = function() {
      this.style.backgroundColor = '#dddddd'
    };
    td.appendChild(document.createTextNode('My Plugins'));
    td = tr.insertCell(-1);
    td.style.width = '150px';
    td.style.borderLeft = 'thick solid #cccccc';
    td.style.cursor = 'pointer';
    td.onmouseover = function() {
      this.style.backgroundColor = '#ffffff';
    };
    td.onmouseout = function() {
      this.style.backgroundColor = ''
    };
    td.appendChild(document.createTextNode('Buy More'));
    td = tr.insertCell(-1);
    td.style.width = '150px';
    td.style.borderLeft = 'thick solid #cccccc';
    td.onmouseover = function() {
      this.style.backgroundColor = '#ffffff';
    };
    td.onmouseout = function() {
      this.style.backgroundColor = ''
    };
    td.appendChild(document.createTextNode('Top100'));

    div.appendChild(iframe);
    div.appendChild(table);
    p._open(div, {
      pos : [DOMUtils.findPos(this)[0], DOMUtils.findPos(this)[1] - 350],
      width : 500
    });
  }
  // Submit
  this._gui.save.onclick = function() {
    page.content = tinyMCE.get('page_content').getContent();
    new RequestUtils()._write(JSON.stringify( [ {
      n : 'pz_page',
      a : [ page ],
      r : []
    } ]), function(result, params) {
      location.reload();
    }, {
      pos : DOMUtils.findPos(this)
    });
  };
  this._gui.plugin_add.onclick = function() {
    new RequestUtils()._write(JSON.stringify( [ {
      n : 'pz_plugin_instance',
      a : [ plugin_instance ],
      r : []
    } ]), function(result, params) {
      location.reload();
    }, {
      pos : DOMUtils.findPos(this)
    });
  };
};

//Html_Page.prototype._adjust = function(iframe) {
//  var boh = iframe.contentDocument.body.offsetHeight;
//  var bsh = iframe.contentDocument.body.scrollHeight;
//  iframe.height = Math.max(boh, bsh) + 100;
//};
